package com.hqyj.springCloundAccount.controller;

import com.github.pagehelper.PageInfo;
import com.hqyj.account.entity.User;
import com.hqyj.account.vo.UserVo;
import com.hqyj.commom.vo.Result;
import com.hqyj.commom.vo.Search;
import com.hqyj.springCloundAccount.server.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/account")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping(value = "/login",consumes = "application/json")
    public Result<User> login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping(value = "/user",consumes = "application/json")
    public Result<User> addUser(@RequestBody User user){
        return userService.addUser(user);

    }

    @PutMapping(value = "/user",consumes = "application/json")
    public Result<User> updateUser(@RequestBody User user){
        System.out.println("************"+user.getId());

        return userService.updateUser(user);
    }

    @GetMapping("/user/{id}")
    public User getUserById(@PathVariable int id){

        return userService.getUserById(id);
    }

    @DeleteMapping("/user/{id}")

    public Result<Object> deleteUserById(@PathVariable int id){
        return userService.deleteUserById(id);
    }

    @PostMapping(value = "/users",consumes = "application/json")
    public PageInfo<User> getUsersBySearch(@RequestBody Search search){
        return userService.getUserBySearch(search);
    }

    /**
     * 127.0.0.1:8761/api/test/userVo/1/1890
     * @param userId
     * @param cityId
     * @return
     */
    @GetMapping("/userVo/{userId}/{cityId}")
    public UserVo getUserVoBy(@PathVariable int userId,@PathVariable int cityId){
       return userService.getUserVoByUserIdAndCityId(userId,cityId);
    }









}
